/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 10, 2011 12:13:23 PM
 */
package carrello.model.entities;

import carrello.model.association.Invoice;
import carrello.util.EntityManagerUtil;
import java.util.Set;
import javax.persistence.*;
@NamedQueries({
        @NamedQuery(name = "getPaymentProcessorById", query = "from PaymentProcessor where processor_id = :s")
        })

@Entity
@Table(name = "PaymentProcessor")
public class PaymentProcessor {
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "processor_id")
    private int    processorId;
    private String name;
    private String url;
    
    @Column(name = "apiUrl")
    private String api;
    
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "processor")
    private Set<Invoice> invoice;

    public PaymentProcessor() {
    }

    public PaymentProcessor(String name, String url, String api) {
        this.name = name;
        this.url = url;
        this.api = api;
    }

    public PaymentProcessor(String name, String url, String api, Set<Invoice> invoice) {
        this.name = name;
        this.url = url;
        this.api = api;
        this.invoice = invoice;
    }

    public int getProcessorId() {
        return processorId;
    }

    public String getApi() {
        return api;
    }

    public void setApi(String api) {
        this.api = api;
    }

    public Set<Invoice> getInvoice() {
        return invoice;
    }

    public void setInvoice(Set<Invoice> invoice) {
        this.invoice = invoice;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    public static PaymentProcessor getPaymentProcessorById ( int id ) {
        PaymentProcessor p = (PaymentProcessor) EntityManagerUtil.getEntityManager().getQuery("getPaymentProcessorById")
                        .setParameter("s", id).uniqueResult();
        return p;
    }
}
